package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.TeacherDao;
import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherService {
    private TeacherDao teacherDao =new TeacherDao();
    public boolean addTeacher(Teacher teacher) {
        return teacherDao.addTeacher(teacher);
    }

    public boolean isExists(String id) {
        Teacher[] teachers= teacherDao.findAllTeacher();
       boolean flag=false;
        for (int i = 0; i < teachers.length; i++) {
            if(teachers[i]!=null&&teachers[i].getId().equals(id)){
                flag=true;
                break;
            }
        }
        return flag;
    }

    public Teacher[] findAllTeacher() {
        Teacher[] teachers=teacherDao.findAllTeacher();
        boolean flag=false;
        for (int i = 0; i < teachers.length; i++) {
            if(teachers[i]!=null){
                flag=true;
                break;
            }
        }
        if(flag){
            return teachers;
        }else{
            return null;
        }

    }

    public void deleteTeacher(String id) {
        teacherDao.deleteTeacher(id);
    }

    public void updateTeacher(Teacher teacher, String id) {
        teacherDao.updateTeacher(teacher,id);
    }
}
